﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
using System.Reflection;

namespace IRC.IRepairClouds.DataLayer.Expressions
{
    public class ElementInitBuilder<T>
    {
        public ElementInit ElementInit { get; private set; }

        internal ElementInitBuilder(ElementInit elementInit)
        {
            ElementInit = ElementInit;
        }

        internal ElementInitBuilder(MethodInfo addMethod, params ExpressionBuilder[] arguments)
        {
            ElementInit = Expression.ElementInit(addMethod, arguments != null ? arguments.Select(i => i.Expression) : null);
        }

        public static implicit operator ElementInit(ElementInitBuilder<T> expressionBuilder)
        {
            return expressionBuilder.ElementInit;
        }

        public static implicit operator ElementInitBuilder<T>(ElementInit elementInit)
        {
            return new ElementInitBuilder<T>(elementInit);
        }
    }
}
